﻿using System.Collections.Generic;
using System.Linq;

namespace MvcApp
{
    public class Region
    {
        private static List<Region> regions = new List<Region>
        {
            new Region { Code = "001", Name = "中国"},
            new Region { Code = "002", Name = "美国"},
            new Region { Code = "011", Name = "北京", ParentCode = "001"},
            new Region { Code = "021", Name = "广州", ParentCode = "001"},
            new Region { Code = "111", Name = "海淀区", ParentCode = "011"},
            new Region { Code = "211", Name = "东城区", ParentCode = "011"},
            new Region { Code = "121", Name = "天河区", ParentCode = "021"},
            new Region { Code = "221", Name = "海珠区", ParentCode = "021"},

            new Region { Code = "012", Name = "佛罗里达州", ParentCode = "002"},
            new Region { Code = "022", Name = "得克萨斯州", ParentCode = "002"},

            new Region { Code = "112", Name = "迈阿密", ParentCode = "012"},
            new Region { Code = "212", Name = "奥兰多", ParentCode = "012"},

            new Region { Code = "122", Name = "休斯敦", ParentCode = "022"},
            new Region { Code = "222", Name = "达拉斯", ParentCode = "022"},
            new Region { Code = "322", Name = "圣安东尼奥", ParentCode = "022"},

        };

        public string Code { get; set; }
        public string Name { get; set; }
        public string ParentCode { get; set; }

        public static IEnumerable< Region> GetAllFirstRegions()
        {
            return regions.Where(r => string.IsNullOrWhiteSpace(r.ParentCode));
        }

        public static IEnumerable<Region> GetChildRegions(string regionCode)
        {
            return regions.Where(r => r.ParentCode == regionCode);
        }
    }
}